/***********************************************************************************
Copy right:	    Coffee Tech.
Author:         jiaoyue
Date:           2021-11-23
Description:    提供共享内存组件
***********************************************************************************/

#ifndef SHMEM_H
#define SHMEM_H

#include "pub_define.h"
#include <sys/ipc.h>
#include <sys/shm.h>

#define SHM_NAME_SZ    32

struct shm_param
{
    int id;                       //共享内存ID
    size_t size;
    void *addr;                   //共享内存地址
    char name[SHM_NAME_SZ+1];     //共享内存key标识
};

union val
{
    int val_int;
    double val_double;
    int val_bool;
};

struct leixing
{
    int type;
    int period;
};

struct mqtt_server
{
    char addr[128];
	int port;
};

struct mb_dev
{
    char addr[128];
	int port;
};

struct stm32
{
    int key;
    char name[128];  // 数据点名称
    int type;        // 数据点类型
    union val value; // 采集的新数据
};

struct modbus
{
    int key;
    char name[128]; // 数据点名称
    int addr;       // Modbus寄存器地址
    int type;       // 数据点类型
    union val value; // 采集的新数据
};

struct dapeng_date
{
    int stm32_count;
    int modbus_count;
    char vs[128];
    struct leixing lx;
    struct mqtt_server ms;
    struct mb_dev md;
    struct stm32 st[10];
    struct modbus mb[10];
};


int shm_init(struct shm_param *para, const char *name, size_t size);
void *shm_getaddr(struct shm_param *para);
void shm_write(const struct shm_param *para, void *data, size_t size);
int shm_del(const struct shm_param *para);

#endif  // SHMEM_H
